package week02

// 589. N 叉树的前序遍历
// https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/

func preorder(root *Node) []int {
	return preorder2(root, []int{})
}

func preorder2(root *Node, ans []int) []int {
	if root == nil {
		return ans
	}
	ans = append(ans, root.Val)
	for _, child := range root.Children {
		ans = preorder2(child, ans)
	}
	return ans
}


type Node struct {
	Val int
	Children []*Node
}